Skip to content

Conversation

knassre-bodo
Copy link
Contributor

Resolves #421.

@knassre-bodo knassre-bodo requested review from a team, hadia206, john-sanchez31 and juankx-bodo and removed request for a team September 15, 2025 17:45
return SQLGlotRelationalVisitor(DatabaseDialect.SQLITE, config)
@pytest.fixture
def sqlglot_relational_visitor(empty_sqlite_tpch_session) -> SQLGlotRelationalVisitor:
return SQLGlotRelationalVisitor(empty_sqlite_tpch_session)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can no longer be module-level since we depend on empty_sqlite_tpch_session

raise PyDoughSessionException(
f"Expected `session` to be a PyDoughSession, got {session.__class__.__name__}."
)
if session.metadata is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are only checking for metadata. Should we check also for session.config and session.database?
Could we build new_session from session in kwargs if it exists, then if metadata, config or database are provided we overwrite them in new_session and finally if any of them is null in new_session then we set that value with its value in active_session.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question, why only check for metadata. Why not config and database?

Copy link
Contributor Author

@knassre-bodo knassre-bodo Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because session.metadata can be None according to the type (GraphMetadata | None), but session.config and session.database cannot.

str, Callable[..., UnqualifiedNode], str, str
],
verbose: bool,
get_sample_graph: graph_fetcher,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we provide the graph as part of the session?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

@knassre-bodo knassre-bodo Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the way this test is written doesn't use sessions, it is just calling pydough.explain directly on metadata objects. The fetcher gets passed into this function (see the fixture metadata_exploration_test_data):

graph_name: str = args[0]
collection_name: str | None = args[1]
property_name: str | None = args[2]
def wrapped_test_impl(fetcher: graph_fetcher, verbose: bool):
        graph: GraphMetadata = fetcher(graph_name)
        if collection_name is None:
            return pydough.explain(graph, verbose=verbose)
        elif property_name is None:
            return pydough.explain(graph[collection_name], verbose=verbose)
        else:
            return pydough.explain(
                graph[collection_name][property_name], verbose=verbose
            )

Copy link
Contributor

@john-sanchez31 john-sanchez31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Just a couple of comments below

ON _s1.o_custkey = customer.c_custkey
ORDER BY
total DESC
3 DESC
Copy link
Contributor

@john-sanchez31 john-sanchez31 Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did these queries change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I was updating the documentation, I also updated the example generated SQL used in the documentation to reflect the most recent version of PyDough (since these are not automatically generated)

Copy link
Contributor

@hadia206 hadia206 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple of questions/comments. Otherwise looks good to me.

raise PyDoughSessionException(
f"Expected `session` to be a PyDoughSession, got {session.__class__.__name__}."
)
if session.metadata is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question, why only check for metadata. Why not config and database?

"Please use `session.load_metadata_graph` to attach a graph to the session."
)
if kwargs:
raise ValueError(f"Unexpected keyword arguments: {kwargs}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar question to Juan's in the line up
What happens is the config and database are added? We should use them.
I understand that the metadata is required but others are optional but what happens if someone included those as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are all required. The difference is that the other two can't be None.

str, Callable[..., UnqualifiedNode], str, str
],
verbose: bool,
get_sample_graph: graph_fetcher,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@knassre-bodo knassre-bodo merged commit f1a9961 into main Oct 7, 2025
10 checks passed
@knassre-bodo knassre-bodo deleted the kian/session_kwarg branch October 7, 2025 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow a session to be passed in as a keyword argument to to_sql and to_df
4 participants